//----------------------------------------------------------------------------
// M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S
//----------------------------------------------------------------------------
// Copyright (C) 2012 - MARIN - All rights reserved - http://www.marin.nl
//----------------------------------------------------------------------------
// Program    : mermaid
// Module     : vbm
// File       : axpy_kernels.h
// Author     : M.A. de Jong
//----------------------------------------------------------------------------

#ifndef AXPY_KERNELS_H
#define	AXPY_KERNELS_H

namespace rrbsolver
{

// y <- a * y + b * x;
template <class T>
__global__ void kernel_axpy(T *y, const T *x, 
    const T a, const T b, const Grid g)
{
    int cgx = g.cx;
    int cgy = g.cy;
    int ld  = g.nx;

    int v_r1 = BORDER_WIDTH + by * By + ty;
    int u_r1 = BORDER_WIDTH + bx * Bx + tx;
    int v_r2 = BORDER_WIDTH2 + cgy + by * By + ty;
    int u_r2 = BORDER_WIDTH2 + cgx + bx * Bx + tx;

    int loc_r1 = ld * v_r1 + u_r1;
    int loc_r2 = ld * v_r2 + u_r2;

    y[loc_r1] = a * y[loc_r1] + b * x[loc_r1];
    y[loc_r2] = a * y[loc_r2] + b * x[loc_r2];
}

} // namespace rrbsolver

#endif // AXPY_KERNELS_H

